// hyb_yl/doctorHome/pages/task_edit/task_edit.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show_state:false,
    ansers:"",
    articles:"",
    checks:"",
    answer_ids:[],
    article_ids:"",
    article_idss:[],
    checklist:[],
    cares:"",
    caress:"",
    care:[],
  },
  show_cont: function () {
    this.setData({
      show_state: !this.data.show_state
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    var that = this;
    that.setData({
      id:id
    })
    that.getDetail();
  },
  // 获取详情
  getDetail:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.suifang_detail",
      data:{
        id:that.data.id
      },
      success:function(res)
      {
        that.setData({
          info:res.data,
          answer_ids:res.data.answer_ids,
          article_ids:res.data.article_ids,
          checklist:res.data.checklist,
          caress:res.data.caress,
          cares:res.data.cares,
          care:res.data.care,
          answers:res.data.answers,
          articles:res.data.articles,
          checks:res.data.checks,
          j_id:res.data.j_id
        })
      }
    })
  },
  // 修改详情
  edit:function(e){
    var that = this;
    var type = e.currentTarget.dataset.type;
    var id = that.data.id;
    wx.navigateTo({
      url: '/hyb_yl/doctorHome/pages/choose_task/choose_task?type='+type+'&names='+that.data.info.userjiaren.names+'&sex='+that.data.info.userjiaren.sex+'&age='+that.data.info.userjiaren.age+'&u_thumb='+that.data.info.user.u_thumb+'&number='+that.data.info.number+'&caozuo=edit',
    })
  },
  add:function(e){
    var that = this;
    var type = e.currentTarget.dataset.type;
    var id = that.data.id;
    wx.navigateTo({
      url: '/hyb_yl/doctorHome/pages/choose_task/choose_task?type='+type+'&names='+that.data.info.userjiaren.names+'&sex='+that.data.info.userjiaren.sex+'&age='+that.data.info.userjiaren.age+'&u_thumb='+that.data.info.user.u_thumb+'&number='+that.data.info.number+'&caozuo=add',
    })
  },
  // 删除任务
  del:function(){
    var that = this;
    var id = that.data.id;
    wx.showModal({
      cancelColor: '提示',
      content:"是否确认删除该任务",
      success:function(con)
      {
        if(con.confirm)
        {
          app.util.request({
            'url':"entry/wxapp/follow.del_suifang",
            data:{
              id:id
            },
            success:function(res)
            {
              wx.navigateBack({})
            }
          })
          
        }
      }
    })
  },
  // 保存任务
  save:function(){
    var that = this;
    var article_idss = that.data.article_idss;
    var answer_ids = that.data.answer_ids;
    var checklist = that.data.checklist;
    var care = that.data.care;
    var id = that.data.id;
    var j_id = that.data.j_id;
    app.util.request({
      'url':"entry/wxapp/follow.save_suifang",
      data:{
        id:id,
        j_id:j_id,
        article_ids:JSON.stringify(article_idss),
        answer_ids:JSON.stringify(answer_ids),
        checklist:JSON.stringify(checklist),
        care:JSON.stringify(care),
      },
      success:function(res)
      {
        if(res.data.code == 1)
        {
          wx.showToast({
            title: '保存成功',
          })
        }else{
          wx.showToast({
            title: '保存失败',
          })
        }
        setTimeout(function(){
          wx.navigateBack({})
        },500)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})